package streamAPI.operators;

import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;
import util.FlinkConstant;


/**
 * @author yue.cao
 * @since 09-28-2020
 */
public class DemoWithFlatMap {

	public static void main(String[] args) throws Exception {
		StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
		env.fromElements(FlinkConstant._Common.SOME_STRING_WITH_SPACE).flatMap(new FlatMapFunction<String, String>() {
			@Override
			public void flatMap(String line, Collector<String> out) throws Exception {
//				Arrays.stream(line.split(" ")).forEach(out::collect);
				for (String word : line.split(" ")) {
					out.collect(word);
				}
			}
		}).print();
		env.execute(DemoWithFlatMap.class.getName());
	}


}
